package com.ruoyi.service.account.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.service.account.entity.CompanyAccountEntity;
import com.ruoyi.service.account.mapper.CompanyAccountMapper;
import com.ruoyi.service.account.service.CompanyAccountService;
import com.ruoyi.service.company.entity.CompanyEntity;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 公司账户 服务实现类
 * </p>
 *
 * @author Zane
 * @since 2025-10-19
 */
@Service
public class CompanyAccountServiceImpl extends
    ServiceImpl<CompanyAccountMapper, CompanyAccountEntity> implements
    CompanyAccountService {

  @Override
  public CompanyAccountEntity getByComId(Long companyId) {
    return getOne(queryWrapper().eq(CompanyAccountEntity::getComId, companyId));
  }

  @Override
  public void buildCompanyAccount(CompanyEntity company) {
    CompanyAccountEntity companyAccountEntity = new CompanyAccountEntity()
        .setComId(company.getComId())
        .setAmount(BigDecimal.ZERO)
        .setLockedAmount(BigDecimal.ZERO)
        .setCreateBy(company.getCreateBy())
        .setCreateTime(LocalDateTime.now())
        .setUpdateBy(company.getUpdateBy())
        .setUpdateTime(LocalDateTime.now());
    this.save(companyAccountEntity);
  }

  @Override
  public BigDecimal getBalance() {
    return this.getBaseMapper().getBalance();
  }

  @Override
  public BigDecimal getLockedAmount() {
    return  this.getBaseMapper().getLockedAmount();
  }

  private LambdaQueryWrapper<CompanyAccountEntity> queryWrapper() {
    return new LambdaQueryWrapper<>();
  }
}
